import { d as defineComponent, aO as useMusicStore, b as useStatusStore, r as ref, i as createBlock, j as openBlock, c5 as __unplugin_components_5, k as unref, Q as nextTick, bI as renderIcon, aY as copyData, Z as debounce, d1 as radioAllProgram, aR as formatSongsList, c$ as playlistAllSongs, b8 as songDetail, ae as Transition, m as withCtx, H as createElementBlock, ac as normalizeClass, n as createVNode, af as createCommentVNode, aV as __unplugin_components_4, aA as Fragment, aB as renderList, c9 as __unplugin_components_2, J as createBaseVNode, a5 as __unplugin_components_1, a8 as toDisplayString, cU as formatNumber, ai as __unplugin_components_0$1, a7 as createTextVNode, bC as withModifiers, a6 as Button, cV as formatTimestamp, ar as __unplugin_components_3, aj as __unplugin_components_11, b4 as __unplugin_components_5$1, K as _export_sfc } from "./stores.js";
import { u as useRouter, p as player, h as __unplugin_components_2$1 } from "./index.js";
import { a as albumDetail } from "./album3.js";
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
  __name: "CoverMenu",
  emits: ["toPlay"],
  setup(__props, { expose: __expose, emit: __emit }) {
    const emit = __emit;
    const router = useRouter();
    const musicStore = useMusicStore();
    const statusStore = useStatusStore();
    const dropdownX = ref(0);
    const dropdownY = ref(0);
    const dropdownShow = ref(false);
    const dropdownOptions = ref([]);
    const openDropdown = async (e, item, type) => {
      try {
        e.preventDefault();
        dropdownShow.value = false;
        nextTick().then(() => {
          dropdownOptions.value = [
            {
              key: "open",
              label: "查看详情",
              props: {
                onClick: () => router.push({
                  name: type,
                  query: { id: item.id }
                })
              },
              icon: renderIcon("Eye")
            },
            {
              key: "play",
              label: "播放",
              show: musicStore.playPlaylistId !== item.id || !statusStore.playStatus,
              props: {
                onClick: () => emit("toPlay", item)
              },
              icon: renderIcon("Play")
            },
            {
              key: "pause",
              label: "暂停",
              show: musicStore.playPlaylistId === item.id && statusStore.playStatus,
              props: {
                onClick: () => emit("toPlay", item)
              },
              icon: renderIcon("Pause")
            },
            {
              key: "line",
              type: "divider"
            },
            {
              key: "copy",
              label: "复制链接",
              props: {
                onClick: () => copyData(`https://music.163.com/#/${type}?id=${item.id}`)
              },
              icon: renderIcon("Link")
            }
          ];
          dropdownX.value = e.clientX;
          dropdownY.value = e.clientY;
          dropdownShow.value = true;
        });
      } catch (error) {
        console.error("右键菜单出现异常：", error);
        window.$message.error("右键菜单出现异常");
      }
    };
    __expose({ openDropdown });
    return (_ctx, _cache) => {
      const _component_n_dropdown = __unplugin_components_5;
      return openBlock(), createBlock(_component_n_dropdown, {
        x: unref(dropdownX),
        y: unref(dropdownY),
        show: unref(dropdownShow),
        options: unref(dropdownOptions),
        class: "search-inp-menu",
        placement: "bottom-start",
        trigger: "manual",
        onSelect: _cache[0] || (_cache[0] = ($event) => dropdownShow.value = false),
        onClickoutside: _cache[1] || (_cache[1] = ($event) => dropdownShow.value = false)
      }, null, 8, ["x", "y", "show", "options"]);
    };
  }
});
const _hoisted_1 = ["onClick", "onContextmenu"];
const _hoisted_2 = { class: "cover" };
const _hoisted_3 = {
  key: 0,
  class: "cover-mask"
};
const _hoisted_4 = {
  key: 1,
  class: "play-count"
};
const _hoisted_5 = { class: "num" };
const _hoisted_6 = {
  key: 1,
  class: "description"
};
const _hoisted_7 = { class: "cover-data" };
const _hoisted_8 = {
  key: 2,
  class: "meta"
};
const _hoisted_9 = {
  key: 0,
  class: "artists text-hidden"
};
const _hoisted_10 = {
  key: 1,
  class: "artists text-hidden"
};
const _hoisted_11 = { class: "cover-item" };
const _hoisted_12 = { class: "cover" };
const _hoisted_13 = { class: "cover-data" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "CoverList",
  props: {
    data: {},
    type: {},
    cols: { default: "3 600:3 800:4 900:5 1200:6 1400:7" },
    loadMore: { type: Boolean },
    loading: { type: Boolean },
    loadingNum: {},
    loadingText: {}
  },
  emits: ["loadMore"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const router = useRouter();
    const musicStore = useMusicStore();
    const statusStore = useStatusStore();
    const coverMenuRef = ref(null);
    const isPlaying = (id) => musicStore.playPlaylistId === id && statusStore.playStatus;
    const goDetail = (item) => {
      router.push({
        name: props.type,
        query: { id: item.id }
      });
    };
    const playList = debounce(
      async (item) => {
        try {
          if (props.type === "video") {
            return router.push({ name: "video", query: { id: item.id } });
          }
          if (musicStore.playPlaylistId === item.id) return player.playOrPause();
          item.loading = true;
          const list = await getListData(item.id);
          player.updatePlayList(list, void 0, item.id);
        } catch (error) {
          console.log("Error to play: ", error);
        } finally {
          item.loading = false;
        }
      },
      300,
      { leading: true, trailing: false }
    );
    const getListData = async (id) => {
      switch (props.type) {
        case "album": {
          const result = await albumDetail(id);
          const ids = result.songs.map((song) => song.id);
          const songRes = await songDetail(ids);
          return formatSongsList(songRes.songs);
        }
        case "playlist": {
          const result = await playlistAllSongs(id, 100);
          return formatSongsList(result.songs);
        }
        case "radio": {
          const result = await radioAllProgram(id, 100);
          return formatSongsList(result.programs);
        }
        default:
          return [];
      }
    };
    return (_ctx, _cache) => {
      const _component_s_image = __unplugin_components_2$1;
      const _component_SvgIcon = __unplugin_components_1;
      const _component_n_text = __unplugin_components_0$1;
      const _component_n_button = Button;
      const _component_n_gi = __unplugin_components_2;
      const _component_n_grid = __unplugin_components_4;
      const _component_n_flex = __unplugin_components_3;
      const _component_n_skeleton = __unplugin_components_11;
      const _component_n_empty = __unplugin_components_5$1;
      return openBlock(), createBlock(Transition, {
        name: "fade",
        mode: "out-in"
      }, {
        default: withCtx(() => [
          _ctx.data.length > 0 ? (openBlock(), createElementBlock("div", {
            key: 0,
            class: normalizeClass(["cover-list", _ctx.type])
          }, [
            createVNode(_component_n_grid, {
              cols: _ctx.cols,
              "x-gap": "20",
              "y-gap": "20"
            }, {
              default: withCtx(() => [
                (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.data, (item, index) => {
                  return openBlock(), createBlock(_component_n_gi, { key: index }, {
                    default: withCtx(() => [
                      createBaseVNode("div", {
                        class: "cover-item",
                        onClick: ($event) => goDetail(item),
                        onContextmenu: ($event) => unref(coverMenuRef)?.openDropdown($event, item, _ctx.type)
                      }, [
                        createBaseVNode("div", _hoisted_2, [
                          (openBlock(), createBlock(_component_s_image, {
                            key: item.cover,
                            src: _ctx.type === "video" ? `${item.cover}?param=464y260` : item.coverSize?.m || item.cover,
                            "default-src": _ctx.type !== "video" ? "/images/album.jpg?assest" : "/images/video.jpg?assest",
                            class: "cover-img",
                            once: ""
                          }, null, 8, ["src", "default-src"])),
                          item.playCount ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
                            _ctx.type !== "album" ? (openBlock(), createElementBlock("div", _hoisted_3)) : createCommentVNode("", true),
                            _ctx.type !== "album" ? (openBlock(), createElementBlock("div", _hoisted_4, [
                              createVNode(_component_SvgIcon, { name: "Play" }),
                              createBaseVNode("span", _hoisted_5, toDisplayString(unref(formatNumber)(item.playCount || 0)), 1)
                            ])) : createCommentVNode("", true)
                          ], 64)) : createCommentVNode("", true),
                          item.description ? (openBlock(), createElementBlock("div", _hoisted_6, [
                            createVNode(_component_n_text, { class: "text-hidden" }, {
                              default: withCtx(() => [
                                createTextVNode(toDisplayString(item.description), 1)
                              ]),
                              _: 2
                            }, 1024)
                          ])) : createCommentVNode("", true),
                          createBaseVNode("div", {
                            class: "play-btn",
                            onClick: _cache[0] || (_cache[0] = withModifiers(() => {
                            }, ["stop"]))
                          }, [
                            createVNode(_component_n_button, {
                              focusable: false,
                              loading: item.loading,
                              secondary: "",
                              circle: "",
                              class: "play",
                              onClick: withModifiers(($event) => unref(playList)(item), ["stop"])
                            }, {
                              icon: withCtx(() => [
                                createVNode(_component_SvgIcon, {
                                  size: 32,
                                  name: isPlaying(item.id) ? "Pause" : "Play"
                                }, null, 8, ["name"])
                              ]),
                              _: 2
                            }, 1032, ["loading", "onClick"])
                          ])
                        ]),
                        createBaseVNode("div", _hoisted_7, [
                          createVNode(_component_n_text, { class: "name text-hidden" }, {
                            default: withCtx(() => [
                              createTextVNode(toDisplayString(item.name), 1)
                            ]),
                            _: 2
                          }, 1024),
                          (_ctx.type === "playlist" || _ctx.type === "radio") && item?.creator?.id ? (openBlock(), createBlock(_component_n_text, {
                            key: 0,
                            class: "creator",
                            depth: "3"
                          }, {
                            default: withCtx(() => [
                              createTextVNode(toDisplayString(item.creator?.name || item.creator || "未知"), 1)
                            ]),
                            _: 2
                          }, 1024)) : createCommentVNode("", true),
                          item.updateTip ? (openBlock(), createBlock(_component_n_text, {
                            key: 1,
                            class: "tip",
                            depth: "3"
                          }, {
                            default: withCtx(() => [
                              createTextVNode(toDisplayString(item.updateTip), 1)
                            ]),
                            _: 2
                          }, 1024)) : createCommentVNode("", true),
                          _ctx.type === "album" ? (openBlock(), createElementBlock("div", _hoisted_8, [
                            createVNode(_component_n_text, {
                              class: "count",
                              depth: "3"
                            }, {
                              default: withCtx(() => [
                                createTextVNode(toDisplayString(item.count || 0) + "首", 1)
                              ]),
                              _: 2
                            }, 1024),
                            createVNode(_component_n_text, {
                              class: "date",
                              depth: "3"
                            }, {
                              default: withCtx(() => [
                                createTextVNode(toDisplayString(unref(formatTimestamp)(item.createTime)), 1)
                              ]),
                              _: 2
                            }, 1024)
                          ])) : createCommentVNode("", true),
                          _ctx.type === "video" && item.artists ? (openBlock(), createElementBlock(Fragment, { key: 3 }, [
                            Array.isArray(item.artists) ? (openBlock(), createElementBlock("div", _hoisted_9, [
                              (openBlock(true), createElementBlock(Fragment, null, renderList(item.artists, (ar, arIndex) => {
                                return openBlock(), createBlock(_component_n_text, {
                                  key: arIndex,
                                  class: "ar"
                                }, {
                                  default: withCtx(() => [
                                    createTextVNode(toDisplayString(ar.name || "未知艺术家"), 1)
                                  ]),
                                  _: 2
                                }, 1024);
                              }), 128))
                            ])) : (openBlock(), createElementBlock("div", _hoisted_10, [
                              createVNode(_component_n_text, { class: "ar" }, {
                                default: withCtx(() => [
                                  createTextVNode(toDisplayString(item.artists || "未知艺术家"), 1)
                                ]),
                                _: 2
                              }, 1024)
                            ]))
                          ], 64)) : createCommentVNode("", true)
                        ])
                      ], 40, _hoisted_1)
                    ]),
                    _: 2
                  }, 1024);
                }), 128))
              ]),
              _: 1
            }, 8, ["cols"]),
            _ctx.loadMore ? (openBlock(), createBlock(_component_n_flex, {
              key: 0,
              class: "load-more",
              justify: "center"
            }, {
              default: withCtx(() => [
                createVNode(_component_n_button, {
                  loading: _ctx.loading,
                  size: "large",
                  strong: "",
                  secondary: "",
                  round: "",
                  onClick: _cache[1] || (_cache[1] = ($event) => emit("loadMore"))
                }, {
                  default: withCtx(() => _cache[2] || (_cache[2] = [
                    createTextVNode(" 加载更多 ")
                  ])),
                  _: 1
                }, 8, ["loading"])
              ]),
              _: 1
            })) : createCommentVNode("", true),
            createVNode(_sfc_main$1, {
              ref_key: "coverMenuRef",
              ref: coverMenuRef,
              onToPlay: unref(playList)
            }, null, 8, ["onToPlay"])
          ], 2)) : _ctx.loading ? (openBlock(), createElementBlock("div", {
            key: 1,
            class: normalizeClass(["cover-list", "loading", _ctx.type])
          }, [
            createVNode(_component_n_grid, {
              cols: _ctx.cols,
              "x-gap": "20",
              "y-gap": "20"
            }, {
              default: withCtx(() => [
                (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.loadingNum || 50, (item) => {
                  return openBlock(), createBlock(_component_n_gi, { key: item }, {
                    default: withCtx(() => [
                      createBaseVNode("div", _hoisted_11, [
                        createBaseVNode("div", _hoisted_12, [
                          createVNode(_component_n_skeleton, { class: "cover-img" })
                        ]),
                        createBaseVNode("div", _hoisted_13, [
                          createVNode(_component_n_skeleton, {
                            text: "",
                            round: "",
                            repeat: 2
                          })
                        ])
                      ])
                    ]),
                    _: 2
                  }, 1024);
                }), 128))
              ]),
              _: 1
            }, 8, ["cols"])
          ], 2)) : (openBlock(), createBlock(_component_n_empty, {
            key: 2,
            description: "空空如也，怎么什么都没有啊",
            size: "large"
          }))
        ]),
        _: 1
      });
    };
  }
});
const __unplugin_components_0 = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-63d5d2a3"]]);
export {
  __unplugin_components_0 as _
};
